package com.hyts.bmsp.plugin;

import java.sql.Connection;

import com.hyts.bmsp.error.ProcessError;
import org.apache.log4j.Logger;

import com.jfinal.kit.PropKit;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.activerecord.IDataSourceProvider;

/**
 * @ClassName: ActiveRecordPlugin
 * @Description: ActiveRecord 是作为 JFinal的 Plugin而存在的，<br>
 * 				  所以使用时需要在 JFinalConfig中配置ActiveRecordPlugin。<br>
 * @author: 李博/Alex
 * @date: 2017-1-8 上午12:16:56
 */
public class ActiveRecordSupportPlugin {

	/**
	 * @fieldName: arPlugin
	 * @fieldType: ActiveRecordPlugin
	 * @Description: TODO
	 */
	private ActiveRecordPlugin arPlugin;
	
	/**
	 * @fieldName: logger
	 * @fieldType: Logger
	 * @Description: Logger日志输出器
	 */
	private static final Logger logger = Logger.getLogger(ActiveRecordSupportPlugin.class);
		
	/**
	 * @Title:ActiveRecordSupportPlugin
	 * 创建ActiveRecord参数信息进行配置数据参数
	 * @param dataSource
	 */
	public ActiveRecordSupportPlugin(IDataSourceProvider dataSource){
		if(dataSource == null)
			throw new ProcessError("传入的DataSourceProvider提供源失败或为空!");
		logger.info("系统加载ActiveRecord插件信息操作......");
		arPlugin = new ActiveRecordPlugin(dataSource);
		//arPlugin.setDialect();
		//arPlugin.setPrimaryKey(tableName, primaryKey);
		arPlugin.setShowSql(PropKit.use("web.properties").getBoolean("showSql",true));
		arPlugin.setTransactionLevel(Connection.TRANSACTION_READ_COMMITTED);
	}

	public ActiveRecordPlugin getArPlugin() {
		return arPlugin;
	}
	
	
}
